let dataMgr = require("./DataMgr");
cc.Class({
    extends: cc.Component,

    properties: {
        scoreNode: cc.Node,
        progressLabel: cc.Label,

    },
    onLoad() {
        this.scoreNodeJs = this.scoreNode.getComponent("Score");
        let data = cc.sys.localStorage.getItem("RunCool_MaxScore")
        if (data == null) {
            data = 1;
        }
        let maxScore = parseInt(data);
        this.maxScoreValue = maxScore + 100;
        this.progressBarComp = this.node.getComponent(cc.ProgressBar);
        this.progressLabel.string = `${Math.floor(0)}%`;
    },
    start() {

    },

    update(dt) {
        let curScore = this.scoreNodeJs.curScore;
        let ratio = curScore / this.maxScoreValue;
        this.progressBarComp.progress = ratio;
        if (ratio >= 1) {
            dataMgr.getInstance().saveData("isOver", false);
            cc.audioEngine.stopMusic();
            cc.director.loadScene("Over");
        }
        this.progressLabel.string = `${Math.floor(ratio * 100)}%`;

    },
});
